home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: twisto.eng.hou.compaq.com!news
- From: Saurabh Dixit <saurabhd@bangate.compaq.com>
- Subject: Re: Mutually referring header files
- Message-ID: <316C36F8.4545@bangate.compaq.com>
- Sender: news@twisto.eng.hou.compaq.com (System Administrator)
- Mime-Version: 1.0
- X-Mailer: Mozilla 2.0 (WinNT; I)
- Content-Type: text/plain; charset=us-ascii
- Organization: Compaq Computer Corporation
- Date: Wed, 10 Apr 1996 22:32:24 GMT
- References: <4ked7q$8g3@dub-news-svc-1.compuserve.com> <lt91g4ouif.fsf@kitz.inferenzsysteme.informatik.th-darmstadt.de>
- X-Nntp-Posting-Host: 172.18.176.8
- Content-Transfer-Encoding: 7bit
-
- I think the following should work
-
- File A.h
- class B; // forward declaration
- class A {
- B* b;
- };
-
- File B.h
- class A; // forward declaration
- class B {
- A* a;
- };
-
- File A.cpp
- #include "A.h"
- #include "B.h"
- ....
-
- File B.cpp
- #include "B.h"
- #include "A.h"
- ....
-
- Note that if you are referring to either class through pointers,
- then you don't have to include the header for one in the other.
- You can include the header for one in the other's implementation
- file instead where you will actually access the object.
-
- Please also refer to Enno Sandner's response of using
- #ifndefs and #defines for class headers ala A_H and B_H in
- case you plan to include either of the class headers in
- multiple source files.
-
- Hope this helps
- --
- Saurabh Dixit ,,,
- Compaq Computer Corporation (o o)
- _____________________________oOOo-(_)-oOOo__________
- I believe the egg came before the chicken...
- xxxx
-